package com.lutao.util;

import com.baidu.aip.ocr.AipOcr;
import net.sf.json.JSONObject;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Master.Lu
 * @version V1.0
 * @name: BaiduCharacterRecognitionUtil
 * @package com.lutao.util
 * @description TODO:
 * @date 2018-01-02 9:30
 */
public class BaiduCharacterRecognitionUtil {
    public static final String APP_ID = "10225732";
    public static final String API_KEY = "GCaHYKEIiiIk7APsvc8i2ykZ";
    public static final String SECRET_KEY = "Xwzl6yy8N3830sSiGM7gvMklChEG00CX";
    public static Map<String,Object> characterRecognition(byte[] file,int type){
        Map<String, Object> map=new HashMap<String,Object>();
        switch (type){
            case 0:
                map = idCardRecognition(file);
                break;
            case 1:
                map = bankCardRecognition(file);
                break;
            case 2:
                map = drivingLicenseRecognition(file);
                break;
            case 3:
                map = vehicleLicenseRecognition(file);
                break;
            case 4:
                map = plateLicenseRecognition(file);
                break;
            case 5:
                map = businessLicenseRecognition(file);
                break;
            case 6:
                map=basicGeneralRecognition(file);
                break;
            default:
                map.put("code","fail");
                map.put("mes","未完待续");
                break;
        }
        return map;
    }
    public static Map<String,Object> characterRecognition(String file,int type){
        Map<String, Object> map=new HashMap<String,Object>();
        switch (type){
            case 0:
                map = idCardRecognition(file);
                break;
            case 1:
                map = bankCardRecognition(file);
                break;
            case 2:
                map = drivingLicenseRecognition(file);
                break;
            case 3:
                map = vehicleLicenseRecognition(file);
                break;
            case 4:
                map = plateLicenseRecognition(file);
                break;
            case 5:
                map = businessLicenseRecognition(file);
                break;
            case 6:
                map=basicGeneralRecognition(file);
                break;
            default:
                map.put("code","fail");
                map.put("mes","未完待续");
                break;
        }
        return map;
    }
    private static Map<String, Object> idCardRecognition(byte[] file){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            String idCardSide = "front";
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("detect_direction", "true");
            options.put("detect_risk", "false");
            org.json.JSONObject response = client.idcard(file,idCardSide,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("words_result"));
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("姓名").toString()), Map.class);
            map.put("name",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("住址").toString()), Map.class);
            map.put("address",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("公民身份号码").toString()), Map.class);
            map.put("cardId",paramMap.get("words").toString());
            map.put("code","success");
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> bankCardRecognition(byte[] file){
        Map<String, Object>  map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            HashMap<String, String> options = new HashMap<String, String>();
            org.json.JSONObject response = client.bankcard(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("result"));
            String bankCardType = object.get("bank_card_type").toString();
            if("0".equals(bankCardType)){
                map.put("code","fail");
                map.put("mes","不能识别");
            }else {
                map.put("code","success");
                map.put("bank_name",object.get("bank_name").toString());
                map.put("bank_card_number",object.get("bank_card_number").toString());
                if("1".equals(bankCardType)){
                    map.put("bank_card_type","借记卡");
                }else if("2".equals(bankCardType)){
                    map.put("bank_card_type","信用卡");
                }
            }
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> drivingLicenseRecognition(byte[] file){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("detect_direction", "true");
            org.json.JSONObject response = client.drivingLicense(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            String errno = object.get("errno").toString();
            if("0".equals(errno)){
                object = JSONObject.fromObject(object.getJSONObject("data"));
                object = JSONObject.fromObject(object.getJSONObject("words_result"));
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("证号").toString()), Map.class);
                map.put("cardId",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("有效期限").toString()), Map.class);
                map.put("validTime",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("准驾车型").toString()), Map.class);
                map.put("quasiDrivingModel",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("有效起始日期").toString()), Map.class);
                map.put("validStartTime",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("住址").toString()), Map.class);
                map.put("address",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("姓名").toString()), Map.class);
                map.put("name",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("国籍").toString()), Map.class);
                map.put("nationality",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("出生日期").toString()), Map.class);
                map.put("birthDate",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("性别").toString()), Map.class);
                map.put("gender",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("初次领证日期").toString()), Map.class);
                map.put("issueDate",paramMap.get("words").toString());
                map.put("code","success");
            }else{
                map.put("code","fail");
                map.put("mes","不能识别");
            }
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> vehicleLicenseRecognition(byte[] file){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("detect_direction", "true");
            options.put("accuracy", "normal");
            org.json.JSONObject response = client.vehicleLicense(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            String errno = object.get("errno").toString();
            if("0".equals(errno)){
                object = JSONObject.fromObject(object.getJSONObject("data"));
                object = JSONObject.fromObject(object.getJSONObject("words_result"));
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("品牌型号").toString()), Map.class);
                map.put("brandModel",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("发证日期").toString()), Map.class);
                map.put("issueDate",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("使用性质").toString()), Map.class);
                map.put("useType",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("发动机号码").toString()), Map.class);
                map.put("engineNumber",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("号牌号码").toString()), Map.class);
                map.put("plateNumber",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("住址").toString()), Map.class);
                map.put("address",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("所有人").toString()), Map.class);
                map.put("name",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("注册日期").toString()), Map.class);
                map.put("birthDate",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("车辆识别代号").toString()), Map.class);
                map.put("recognitionId",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("车辆类型").toString()), Map.class);
                map.put("carType",paramMap.get("words").toString());
                map.put("code","success");
            }else{
                map.put("code","fail");
                map.put("mes","不能识别");
            }
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> plateLicenseRecognition(byte[] file){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("multi_detect", "true");
            org.json.JSONObject response = client.plateLicense(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("words_result"));
            map.put("number",object.get("number"));
            map.put("color",object.get("color"));
            map.put("code","success");
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> businessLicenseRecognition(byte[] file){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            HashMap<String, String> options = new HashMap<String, String>();
            org.json.JSONObject response = client.businessLicense(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("words_result"));
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("单位名称").toString()), Map.class);
            map.put("organizationName",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("法人").toString()), Map.class);
            map.put("legalPerson",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("地址").toString()), Map.class);
            map.put("address",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("有效期").toString()), Map.class);
            map.put("validTime",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("证件编号").toString()), Map.class);
            map.put("certificateId",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("社会信用代码").toString()), Map.class);
            map.put("creditCode",paramMap.get("words").toString());
            map.put("code","success");
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> basicGeneralRecognition(byte[] file){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("language_type", "CHN_ENG");
            options.put("detect_direction", "true");
            options.put("detect_language", "true");
            options.put("probability", "true");
            org.json.JSONObject response = client.basicGeneral(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("words_result"));

            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("单位名称").toString()), Map.class);
            map.put("organizationName",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("法人").toString()), Map.class);
            map.put("legalPerson",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("地址").toString()), Map.class);
            map.put("address",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("有效期").toString()), Map.class);
            map.put("validTime",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("证件编号").toString()), Map.class);
            map.put("certificateId",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("社会信用代码").toString()), Map.class);
            map.put("creditCode",paramMap.get("words").toString());
            map.put("code","success");
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> idCardRecognition(String fileSrc){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            String idCardSide = "front";
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("detect_direction", "true");
            options.put("detect_risk", "false");
            String file = fileSrc;
            org.json.JSONObject response = client.idcard(file, idCardSide, options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("words_result"));
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("姓名").toString()), Map.class);
            map.put("name",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("住址").toString()), Map.class);
            map.put("address",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("公民身份号码").toString()), Map.class);
            map.put("cardId",paramMap.get("words").toString());
            map.put("code","success");
        }catch (Exception e){
            map.put("code","fail");
            return map;
        }
        return map;
    }
    private static Map<String, Object> bankCardRecognition(String fileSrc){
        Map<String, Object>  map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            HashMap<String, String> options = new HashMap<String, String>();
            String file = fileSrc;
            org.json.JSONObject response = client.bankcard(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("result"));
            String bankCardType = object.get("bank_card_type").toString();
            if("0".equals(bankCardType)){
                map.put("code","fail");
                map.put("mes","不能识别");
            }else {
                map.put("code","success");
                map.put("bank_name",object.get("bank_name").toString());
                map.put("bank_card_number",object.get("bank_card_number").toString());
                if("1".equals(bankCardType)){
                    map.put("bank_card_type","借记卡");
                }else if("2".equals(bankCardType)){
                    map.put("bank_card_type","信用卡");
                }
            }
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> drivingLicenseRecognition(String fileSrc){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            String file = fileSrc;
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("detect_direction", "true");
            org.json.JSONObject response = client.drivingLicense(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            String errno = object.get("errno").toString();
            if("0".equals(errno)){
                object = JSONObject.fromObject(object.getJSONObject("data"));
                object = JSONObject.fromObject(object.getJSONObject("words_result"));
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("证号").toString()), Map.class);
                map.put("cardId",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("有效期限").toString()), Map.class);
                map.put("validTime",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("准驾车型").toString()), Map.class);
                map.put("quasiDrivingModel",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("有效起始日期").toString()), Map.class);
                map.put("validStartTime",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("住址").toString()), Map.class);
                map.put("address",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("姓名").toString()), Map.class);
                map.put("name",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("国籍").toString()), Map.class);
                map.put("nationality",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("出生日期").toString()), Map.class);
                map.put("birthDate",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("性别").toString()), Map.class);
                map.put("gender",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("初次领证日期").toString()), Map.class);
                map.put("issueDate",paramMap.get("words").toString());
                map.put("code","success");
            }else{
                map.put("code","fail");
                map.put("mes","不能识别");
            }
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> vehicleLicenseRecognition(String fileSrc){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            String file = fileSrc;
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("detect_direction", "true");
            options.put("accuracy", "normal");
            org.json.JSONObject response = client.vehicleLicense(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            String errno = object.get("errno").toString();
            if("0".equals(errno)){
                object = JSONObject.fromObject(object.getJSONObject("data"));
                object = JSONObject.fromObject(object.getJSONObject("words_result"));
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("品牌型号").toString()), Map.class);
                map.put("brandModel",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("发证日期").toString()), Map.class);
                map.put("issueDate",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("使用性质").toString()), Map.class);
                map.put("useType",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("发动机号码").toString()), Map.class);
                map.put("engineNumber",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("号牌号码").toString()), Map.class);
                map.put("plateNumber",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("住址").toString()), Map.class);
                map.put("address",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("所有人").toString()), Map.class);
                map.put("name",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("注册日期").toString()), Map.class);
                map.put("birthDate",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("车辆识别代号").toString()), Map.class);
                map.put("recognitionId",paramMap.get("words").toString());
                paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("车辆类型").toString()), Map.class);
                map.put("carType",paramMap.get("words").toString());
                map.put("code","success");
            }else{
                map.put("code","fail");
                map.put("mes","不能识别");
            }
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> plateLicenseRecognition(String fileSrc){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            String file = fileSrc;
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("multi_detect", "true");
            org.json.JSONObject response = client.plateLicense(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("words_result"));
            map.put("number",object.get("number"));
            map.put("color",object.get("color"));
            map.put("code","success");
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> businessLicenseRecognition(String fileSrc){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            String file = fileSrc;
            HashMap<String, String> options = new HashMap<String, String>();
            org.json.JSONObject response = client.businessLicense(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("words_result"));
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("单位名称").toString()), Map.class);
            map.put("organizationName",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("法人").toString()), Map.class);
            map.put("legalPerson",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("地址").toString()), Map.class);
            map.put("address",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("有效期").toString()), Map.class);
            map.put("validTime",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("证件编号").toString()), Map.class);
            map.put("certificateId",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("社会信用代码").toString()), Map.class);
            map.put("creditCode",paramMap.get("words").toString());
            map.put("code","success");
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
    private static Map<String, Object> basicGeneralRecognition(String fileSrc){
        Map<String, Object> paramMap = null, map=new HashMap<String,Object>();
        try {
            // 初始化一个AipOcr
            AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
            // 可选：设置网络连接参数
            client.setConnectionTimeoutInMillis(2000);
            client.setSocketTimeoutInMillis(60000);
            String file = fileSrc;
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("language_type", "CHN_ENG");
            options.put("detect_direction", "true");
            options.put("detect_language", "true");
            options.put("probability", "true");
            org.json.JSONObject response = client.basicGeneral(file,options);
            JSONObject object = JSONObject.fromObject(response.toString());
            object = JSONObject.fromObject(object.getJSONObject("words_result"));

            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("单位名称").toString()), Map.class);
            map.put("organizationName",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("法人").toString()), Map.class);
            map.put("legalPerson",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("地址").toString()), Map.class);
            map.put("address",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("有效期").toString()), Map.class);
            map.put("validTime",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("证件编号").toString()), Map.class);
            map.put("certificateId",paramMap.get("words").toString());
            paramMap = (Map) JSONObject.toBean(net.sf.json.JSONObject.fromObject(object.get("社会信用代码").toString()), Map.class);
            map.put("creditCode",paramMap.get("words").toString());
            map.put("code","success");
        }catch (Exception e){
            map.put("code","fail");
            map.put("mes","识别异常");
            return map;
        }
        return map;
    }
}
